package net.sxnic.ugr.permission;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sxinfo.core.entity.AbstractEntity;
import net.sxnic.ugr.resource.Resource;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 
 * Comments: 权限表
 * <p>
 * Author：孙宇飞
 * <p>
 * Create Date：2013-3-10
 * <p>
 * 
 * 
 */
@Entity
@Table(name = "ugr_permission")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Permission extends AbstractEntity {

	private static final long serialVersionUID = 4968351151515850346L;

	/**
	 * 有管理权限的 前缀
	 */
	public static final String SYSTEM_ADMIN = "admin";

	/**
	 * 权限“读取”
	 */
	public static final String READ = "_view";

	/**
	 * 权限“更新”
	 */
	public static final String UPDATE = "_update";

	/**
	 * 权限“删除”
	 */
	public static final String DELETE = "_delete";

	/**
	 * 权限“创建”
	 */
	public static final String CREATE = "_create";

	/**
	 * 权限“读取列表”
	 */
	public static final String BROWSE = "_browse";

	/**
	 * 权限“所有”
	 */
	public static final String ANY = "_*";

	/**
	 * 唯一标示权限的编码，可以置换url的/为下划线，比如/front/task/list.jspa -> front_task_list
	 */
	@Column(unique = true, nullable = false)
	private String code;

	/**
	 * 权限
	 */
	private String url;

	/**
	 * 权限说明
	 */
	private String beizhu;

	/**
	 * 操作
	 */
	private String opt;

	/**
	 * 所属子系统code ,如果未空表示公用，如果有值则表示子系统专用
	 */
	private String siteCode;

	@ManyToOne(fetch = FetchType.LAZY)
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private Resource res;

	/**
	 * 默认构造器
	 */
	public Permission() {
		super();
	}

	public void treatUrl() {

	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getOpt() {
		return opt;
	}

	public void setOpt(String opt) {
		this.opt = opt;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getBeizhu() {
		return beizhu;
	}

	public void setBeizhu(String beizhu) {
		this.beizhu = beizhu;
	}

	public Resource getRes() {
		return res;
	}

	public void setRes(Resource res) {
		this.res = res;
	}

	public String getSiteCode() {
		return siteCode;
	}

	public void setSiteCode(String siteCode) {
		this.siteCode = siteCode;
	}

	/**
	 * 构造器
	 * 
	 * @param operation
	 *            操作标识
	 * @param entity
	 *            Entity
	 */
	// public Permission(String operation, Object entity) {
	// this();
	//
	// this.operation = operation;
	//
	// try {
	// Method method = entity.getClass()
	// .getMethod("getId", new Class[] {});
	// Object result = method.invoke(entity, new Object[] {});
	// this.name = operation + ":" + entity.getClass().getName() + ":"
	// + result.toString();
	// } catch (Exception e) {
	// throw new IllegalArgumentException("Object of class '"
	// + entity.getClass()
	// + "' does not provide the required getId() method: "
	// + entity, e);
	// }
	//
	// this.entity = entity;
	// }

}
